/*
 * Copyright 2002-2006 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.tigris.jasmincc.implementation;

import org.tigris.jasmincc.framework.*;
import org.tigris.mappedlexer.validator.VerifyHub;

public class ParserClassDefinitionProduction extends LexerSwitchingProduction {

	protected JavaCCModel javaccModel = null;

	protected Coordinator coordinator = null;

	@Override
	public void onParse() throws Exception {
		lexer.setCharOutputSequence(javaccModel.getParserClass());

		tk = lexer.nexttok(JAVACC_PARSER_BEGIN);
		tk = lexer.nexttok(SYM_LEFT_ROUND_BRACE);
		tk = lexer.nexttok(VerifyHub.IDENTIFIER);

		String parserName = tk;
		lexer.nexttok(SYM_RIGHT_ROUND_BRACE); // for ')', but is it necessar?
		tk = lexer.skipTo(JAVACC_PARSER_END);
		lexer.print(tk);
		tk = lexer.nexttok(SYM_LEFT_ROUND_BRACE);
		tk = lexer.nexttok(VerifyHub.IDENTIFIER);
		if (parserName.equals(tk)) {
			// TODO what to do if the parser name is correct?
			tk = lexer.nexttok(SYM_RIGHT_ROUND_BRACE);
		} else {
			// parser name is different in begin and end
			lexer.error(parserName);
		}
		lexer.print("\n");
	}

	/**
	 * 
	 * @param coordinator
	 */
	public void setCoordinator(Coordinator coordinator) {
		this.coordinator = coordinator;
	}

	/**
	 * @param javaccModel
	 *            the javaccModel to set
	 */
	public void setJavaccModel(JavaCCModel javaccModel) {
		this.javaccModel = javaccModel;
	}

}
